import { Module } from '@nestjs/common';
import { TestModule } from './modules/test/test.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { LoginModule } from './modules/login/login.module';
import { AuthModule } from './auth/auth.module'
import { RedisModule } from './redis/redis.module';
import { OrgModule } from './modules/system/organization/org.module';
import { MenuModule } from './modules/system/menu/menu.module';

@Module({
  imports: [
    // 加载环境变量模块
    ConfigModule.forRoot({
      isGlobal: true, // 全局使用模块
      envFilePath: '.env.development'
    }),
    // 连接 Redis
    RedisModule,
    // 校验模块
    AuthModule,
    // 测试模块
    // TestModule,
    // 登录模块
    LoginModule,
    // 组织架构模块
    OrgModule,
    // 菜单管理模块
    MenuModule,
    // 连接 postgres 数据库
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        type: config.get('DABABASE_ORM_TYPE') as any,
        host: config.get('DABABASE_ORM_HOST'),
        port: Number(config.get('DABABASE_ORM_PORT')),
        username: config.get('DABABASE_ORM_USERNAME'),
        password: config.get('DABABASE_ORM_PASSWORD'),
        database: config.get('DABABASE_ORM_DATABASE') as string,
        autoLoadEntities: true,
        logging: true
      })
    }),
  ],
  providers: [],
  exports: []
})
export class AppModule { }
